﻿using D.B.Data.API.Applications.Command.MenusCommand;
using D.B.Data.Domain;
using D.B.Data.ErrorCode;
using D.B.Data.Infrastructuse;
using MediatR;

namespace D.B.Data.API.Applications.CommandHandler.MenusCommandHandler
{
    public class QuerMenusNameCommandHandler : IRequestHandler<QuerMenusNameCommand, APIResult<List<MenusModel>>>
    {
        private readonly IBaseRepository<MenusModel> baseRepository;

        public QuerMenusNameCommandHandler(IBaseRepository<MenusModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<List<MenusModel>>> Handle(QuerMenusNameCommand request, CancellationToken cancellationToken)
        {
            var res = baseRepository.GetAll().Where(s => !s.IsDel);
            APIResult<List<MenusModel>> result = new APIResult<List<MenusModel>>();
            result.Code = EnumCode.Ok;
            result.Data = res.ToList();
            result.Msg = "查询成功";

            return Task.FromResult(result);
        }
    }
}
